﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Jayden.Dll.Cards.Poker;

namespace Jayden.Windows.PokerClient
{
	public partial class SitInCashGameForm : Form
	{
		public PokerCurrency Currency = PokerCurrency.EUR;
		public ulong Stack = 0;
		public ulong Bankroll = 0;

		public SitInCashGameForm()
		{
			InitializeComponent();
		}

		public ulong Amount
		{
			get
			{
				ulong value;
				Currency.TryParseAmout(tbAmount.Text, out value);
				return value;
			}
			set
			{
				tbAmount.Text = Currency.ToString(value, false);
			}
		}

		private void bOk_Click(object sender, EventArgs e)
		{
			DialogResult = System.Windows.Forms.DialogResult.OK;
			Close();
		}

		public DialogResult ShowDialog(PokerClientForm clientForm)
		{
			Text = clientForm.PokerTable.View.TableName;
			// todo use the tableinfo
			ulong min = (clientForm.PokerTable.View.BigBlind * 50);
			ulong max = (clientForm.PokerTable.View.BigBlind * 200);
			if (min > Stack)
				min -= Stack;
			else
				min = 0;
			if (max > Stack)
				max -= Stack;
			else
				max = 0;
			if (max > 0)
			{
				string format = "You have {2} on your bankroll.\r\n - Enter your {3} amount, between {0} and {1}.";
				if (PokerCurrency.Play == Currency)
					format = "Enter your {3} amount, between {0} and {1}.";
				lText.Text = string.Format(format, Currency.ToString(min), Currency.ToString(max), Currency.ToString(Bankroll), Stack == 0 ? "buy-in" : "re-buy");
				tbAmount.Text = Currency.ToString(clientForm.PokerTable.View.BigBlind * 100, false);
				ulong amount = 0;
				DialogResult result;
				do
				{
					result = ShowDialog((IWin32Window)clientForm);
					amount = Amount;
				} while (result == System.Windows.Forms.DialogResult.OK && (amount == 0 || amount < min || amount > max || amount > Bankroll));
				return result;
			}
			else
				return System.Windows.Forms.DialogResult.Abort;
		}
	}
}
